package cn.edu.cqupt.educationfoundation.votingsystem.service.impl;

import cn.edu.cqupt.educationfoundation.votingsystem.common.excepction.PermissionException;
import cn.edu.cqupt.educationfoundation.votingsystem.dao.AdminDao;
import cn.edu.cqupt.educationfoundation.votingsystem.model.dto.AdminDto;
import cn.edu.cqupt.educationfoundation.votingsystem.model.po.AdminPo;
import cn.edu.cqupt.educationfoundation.votingsystem.model.vo.AdminVo;
import cn.edu.cqupt.educationfoundation.votingsystem.service.BackManageService;
import cn.edu.cqupt.educationfoundation.votingsystem.util.ServerUtil;
import cn.edu.cqupt.educationfoundation.votingsystem.util.TransformUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author :DengSiYuan
 * @date :2019/10/25 21:49
 * @desc :
 */
@Slf4j
@Service
public class BackManageServiceImpl implements BackManageService {

    @Resource
    private AdminDao adminDao;

    @Override
    public AdminVo adminLogin(AdminDto adminDto){
        try {
            AdminPo adminPo = adminDao.selectAdminByNameAndPassword(adminDto.getAdminName(),adminDto.getPassword());
            ServerUtil.isNotNull(adminPo);
            return (AdminVo) TransformUtil.transformOne(adminPo,new AdminVo());
        }catch (Exception e){
            log.error("adminLogin->{}",e.getMessage());
            throw new PermissionException("用户名密码有误！！");
        }

    }

}
